package Day3;

import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class JavaClass {
    String name;
    String dirTeacher;
    String manageTeacher;
    String startDate;
    //班级的学生
    String names[] = new String[30];
    int count = 0;
    //String ids[]=new String[30];
    // String phones[]=new String[30];
    //介绍一下班级情况
    public void selfIntro() {
        System.out.println("这是" + name);
        System.out.println("指导老师" + dirTeacher);
        System.out.println("班主任" + manageTeacher);
        System.out.println("于" + startDate + "开班");
        System.out.println("学生信息如下：");
        for (int i = 0; i < names.length; i++) {
            if (names[0] == null){
                System.out.println("暂时没有消息");
                break;
            }
            if (names[i] == null){
                System.out.println("");
                break;
            }

            System.out.print(names[i] + " ");
        }
        System.out.println();
    }

    /**
     * 新生加入班级
     */
    public void add(String newName) {
        //循环，找到数组的空位置
        for (int i = 0; i < names.length; i++) {
            if (names[i] == null) {
                names[i] = newName;
                count++;
                return;
            }
            if (names[i].equals(newName)){
                System.out.println("该名字已存在！");
                return;
            }
        }
        System.out.println("加人失败，没有空位子了");
    }
    //根据名字查找在不在
    public boolean  search(String n){
        for (int i = 0; i < names.length; i++) {
            if(names[i]==null){
                return false;
            }
            if(names[i].equals(n)){
                return true;
            }
        }
        return false;
    }
    //按照范围查找学生
    public boolean search2(String n,int start,int end){
        for (int i = start; i <=end&&i>0&&end< names.length ; i++) {
            if (names[i]==null){
                return false;
            }
            if (names[i].equals(n)){
                return true;
            }
        }
        return false;
    }
    //添加查找指定位置的学生姓名的方法
    public String find(int index){
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < names.length ; i++) {
            if (names[index-1]!=null){
                return names[index-1];
            }
        }
        return "没有找到";
    }
    // 修改学生的方法,要求学生姓名不能重复(不考虑重名的情况)
    public boolean change(String oldName,String newName){
        for (int i = 0; i <names.length ; i++) {
            if (names[i].equals(oldName)){
                names[i]=newName;
                return true;
            }
            if (names[i].equals(newName)){
                return false;
            }
        }
        return false;
    }

}
